#!/usr/bin/env sh

set -e

# Print the usage when none arguments are provided.
if [ "$#" -eq 0 ]; then
    cat <<EOF
Updates the Go version of the project to <version>.

Usage:
    $0 <version>
Examples:
    $0 1.21
EOF
    exit 0
fi

. "$(dirname "$0")/utils"

version=$1

directories=(
    "" # Parent path
    "api"
    "cli"
    "ssh"
    "agent"
    "tests"
)

for dir in "${directories[@]}"; do
    abs_path="$SHELLHUB_PATH/$dir"
    echo "Processing directory: $abs_path"
    cd "$abs_path" || { echo "Failed to enter directory $abs_path"; exit 1; }

    go mod edit -go=$version
    go mod tidy

    echo "Completed processing directory: $abs_path"
done

echo "Script execution completed."
